#encoding:utf-8

from tkinter import *
import time
import client_socket as cl	#网络套接字模块
import sql_operation as sql	#数据库操作模块
import main_itface as mi	#主功能界面模块
import register as reg		#注册模块
import exit					#退出模块

def login():
	x = var1.get()#获取用户输入账号
	y = var2.get()#获取用户输入的密码
	if x != '':
		if y != '':
			#data_c = dc.Data_conding()
			msg = cl.Data_Val('login_qy',x,y)
			if msg == '登陆成功':
				Label(win,text = msg,fg='green',width=25).grid(row=0,column=0,padx=130,pady=175)
				time.sleep(1)
				win.destroy()
				mi.main_interface()
				
			else:
				Label(win,text = msg,fg='red',width=25).grid(row=0,column=0,padx=130,pady=175)
		else:
			Label(win,text = '请输入密码',fg='red',width=25).grid(row=0,column=0,padx=130,pady=175)
	else:
		Label(win,text = '请输入账号',fg='red',width=25).grid(row=0,column=0,padx=130,pady=175)



win = Tk()
win.title('Linux运维管理系统 V 0.1.0')
#win.geometry('400x300')
#frame = Frame(win,width=400,height=300)
sw = win.winfo_screenwidth()#获取屏幕宽度
sh = win.winfo_screenheight()#获取屏幕高度
x = (sw-400)/2#获取减去程序所占宽度后屏幕一半的宽度
y = (sh-300)/2#获取减去程序所占高度后屏幕一半的高度
win.geometry('400x300+%d+%d'%(x,y))#设置窗口大小和显示位置
win.resizable(0,0)#固定窗口大小
var1 = StringVar()#获取用户输入
var2 = StringVar()

Label(win,text = "账号:",font = ("Heiti",16,"bold")).place(x = 70,y = 100)
Entry(win,bd = 3,width = 17,font = ("Heiti",16),textvariable = var1).place(x = 130,y = 100)

Label(win,text = "密码:",font = ("Heiti",16,"bold")).place(x = 70,y = 140)
Entry(win,bd = 3 ,width = 17,font = ("Heiti",16),show="●",textvariable = var2).place(x = 130,y = 140)


Button(win,text = "登陆",font = ("Heiti",12),command = login).place(x = 130,y = 200)
Button(win,text = "注册",font = ("Heiti",12),command = reg.register).place(x = 190,y = 200)
Button(win,text = "退出",font = ("Heiti",12),command = exit.m_exit).place(x = 250,y = 200)
'''
frame.bind('<Key-\r>',Login)
frame.bind('<Escape>',Exit)
frame.focus_set()
frame.pack()
'''
win.mainloop()